castiga_romaniafandomcom_ro-20200214-history
Modul:Infobox
-- This module implements -- local p = {} local getArgs = require('Modul:Arguments').getArgs local StringUtils = require('Modul:StringUtils') local args = {} p._infobox = function(origArgs) local child = origArgs"child" or "no" local bodyclass = origArgs"bodyclass" or "infocaseta" local antet = origArgs"antet" or "default" local aboveclass = origArgs"aboveclass" or antet local abovestyle = origArgs"abovestyle" or "" local culoare_cadru = origArgscadru" or "F5F5DC" local culoare_text = origArgstext" or "000000" local titlestyle = origArgs"titlestyle" or "" local title = origArgs"title" or "" local above = origArgs"above" or "" local parentColSpanArg = origArgs'parent_colspan' local parentColSpan if parentColSpanArg and mw.ustring.gsub(parentColSpanArg, '%d+', '', 1) '' then parentColSpan = tonumber(parentColSpanArg) else parentColSpan = 2 end local wikidataEnabled = origArgs"wikidata" or "" local out = "" if child ~= "yes" then out = out .. " " -- caption out = out .. tostring(mw.html.create('tr') :tag('td') :attr('colspan', '2') :addClass('antet ' .. aboveclass) :css('background-color', StringUtils._prependIfMissing({culoare_cadru, '#'})) :css('color', StringUtils._prependIfMissing({culoare_text, '#'})) :cssText(titlestyle) :wikitext(title)) -- header if above ~= "" then local aboveTr = mw.html.create('tr'):tag('td') :attr('colspan', '2') :addClass(aboveclass) :css('text-align', 'center') :css('font-size', '125%') :css('font-weight', 'bold') :cssText(abovestyle) :wikitext(above):allDone() out = out .. tostring(aboveTr) end else if title ~= "" then out = out .. "\'\'\'" .. title .. "\'\'\'" end end --subheaders local subheaders = {} subheaders1 = origArgs"subheader" or origArgs"subheader1" or "" local subhIndex = 2 while (origArgs.. tostring(subhIndex) or "") ~= "" do subheaderssubhIndex = origArgs.. tostring(subhIndex) or "" subhIndex = subhIndex + 1 end local subheaderstyle = origArgs"subheaderstyle" or "" local subheaderclass = origArgs"subheaderclass" or "" for subHeaderIdx = 1,#subheaders do if subheaderssubHeaderIdx ~= "" then local subhTr = mw.html.create('tr'):tag('td'):attr('colspan', tostring(parentColSpan)) :addClass(subheaderclass) :css('text-align', 'center') :cssText(subheaderstyle) :wikitext(subheaderssubHeaderIdx):allDone() out = out .. tostring(subhTr) end end --images local images = {} local captions = {} images1 = origArgs"image" or "" captions1 = origArgs"caption" or "" local imgIndex = 2 while (origArgs.. tostring(imgIndex) or "") ~= "" do imagesimgIndex = origArgs.. tostring(imgIndex) captionsimgIndex = origArgs.. tostring(imgIndex) or "" imgIndex = imgIndex + 1 end local imageclass = origArgs"imageclass" local imagestyle = origArgs"imagestyle" local captionstyle = origArgs"captionstyle" for i = 1,#images do if imagesi ~= "" then local imageRow = mw.html.create('tr') local imageTd = imageRow :tag('td'):attr('colspan', tostring(parentColSpan)) :addClass(imageclass) :css('text-align', 'center') :cssText(imagestyle) :wikitext(imagesi) if captionsi ~= "" then imageTd:tag('br') imageTd:tag('span'):cssText(captionstyle) :wikitext(captionsi) end out = out .. tostring(imageRow) end end -- rows local labelstyle = origArgs"labelstyle" or "" local datastyle = origArgs"datastyle" or "" local headerstyle = origArgs"headerstyle" or "" local elementIndex = 1 local headers = {} local data = {} local labels = {} local classes = {} local styles = {} local lblstyles = {} local processingOrder = {} for k,v in pairs(origArgs) do local headerStart local headerEnd local labelStart local labelEnd local dataStart local dataEnd local styleStart local styleEnd local lblStyleStart local lblStyleEnd headerStart, headerEnd = mw.ustring.find(k, "header") labelStart, labelEnd = mw.ustring.find(k, "label") dataStart, dataEnd = mw.ustring.find(k, "data") styleStart, styleEnd = mw.ustring.find(k, "style") lblStyleStart, lblStyleEnd = mw.ustring.find(k, "lblstyle") local nr = "" if dataStart 1 then nr = mw.ustring.sub(k, 1 + dataEnd, mw.ustring.len(k)) elseif labelStart 1 then nr = mw.ustring.sub(k, 1 + labelEnd, mw.ustring.len(k)) elseif headerStart 1 then nr = mw.ustring.sub(k, 1 + headerEnd, mw.ustring.len(k)) elseif styleStart 1 then nr = mw.ustring.sub(k, 1 + styleEnd, mw.ustring.len(k)) elseif lblStyleStart 1 then nr = mw.ustring.sub(k, 1 + lblStyleEnd, mw.ustring.len(k)) end if nr ~= "" and processingOrdernr nil and tonumber(nr) ~= nil then headerselementIndex = origArgs.. nr or "" labelselementIndex = origArgs.. nr or "" dataelementIndex = origArgs.. nr or "" classeselementIndex = origArgs.. nr or "" styleselementIndex = origArgs.. nr or "" lblstyleselementIndex = origArgs.. nr or "" processingOrdertonumber(nr) = elementIndex elementIndex = elementIndex + 1 end end local processingElement = 1 while processingElement <= table.maxn(processingOrder) do elementIndex = processingOrderprocessingElement if elementIndex ~= nil then local crtHeader = headerselementIndex local crtData = dataelementIndex local crtLabel = labelselementIndex local crtLblStyle = lblstyleselementIndex local crtClass = classeselementIndex local crtStyle = styleselementIndex if crtHeader ~= "" then local headerTr = mw.html.create('tr') local headerTh = headerTr:tag('th') :attr('colspan', tostring(parentColSpan)) :css('text-align', 'center') :css('background-color', StringUtils._prependIfMissing({culoare_cadru, '#'})) :css('color', StringUtils._prependIfMissing({culoare_text, '#'})) :cssText(headerstyle) :wikitext(crtHeader) out = out .. tostring(headerTr) elseif crtLabel ~= "" then if crtData ~= "" then local dataAndLabelTr = mw.html.create('tr') :tag('th'):cssText(labelstyle):cssText(crtLblStyle) :wikitext(crtLabel):done() :tag('td') :attr('colspan', tostring(parentColSpan - 1)) :addClass(crtClass) :cssText(datastyle):cssText(crtStyle) :wikitext(crtData):allDone() out = out .. tostring(dataAndLabelTr) end elseif crtData ~= "" then local dataTr = mw.html.create('tr') :tag('td'):attr('colspan', tostring(parentColSpan)) :addClass(crtClass) :css('text-align', 'center') :cssText(datastyle) :cssText(crtStyle) :wikitext(crtData):allDone() out = out .. tostring(dataTr) end end processingElement = processingElement + 1 end --below local belowstyle = origArgs"belowstyle" or "" local below = origArgs"below" or "" if below ~= "" then out = out .. tostring(mw.html.create('tr') :tag('td') :attr('colspan', tostring(parentColSpan)) :css('text-align', 'center') :cssText(belowstyle) :wikitext(below)) end --tnavbar local name = origArgs"name" or "" local navbar = origArgs"navbar" if name ~= "" and navbar ~= 'false' then local navBarTr = mw.html.create('tr'):tag('td') :css('text-align', 'right') :attr('colspan', tostring(parentColSpan)) :wikitext(mw.getCurrentFrame():expandTemplate{title = "Tnavbar", args = { name }}):done() out = out .. tostring(navBarTr) end if child ~= "yes" then local doc = origArgs"doc" or "" if doc ~= "" then local infodocTr = mw.html.create('tr'):wikitext(mw.getCurrentFrame():expandTemplate{title = "infodoc", args = {colspan = tostring(parentColSpan), culoare = culoare_cadru, link = doc, wikidata = wikidataEnabled }}) out = out .. tostring(infodocTr) end out = out .. " " end return out end p.infobox = function(frame) local origArgs = getArgs(frame) return p._infobox(origArgs) end return p